from fastapi import APIRouter
from re_common.baselibrary.utils.core.mlamada import bools_string

from apps.core.m_route import ContextIncludedRoute
from apps.core.return_info import ReturnInfo
from apps.sql_app.database import proxys_sql_conn

router = APIRouter(route_class=ContextIncludedRoute)



@router.get("/getproxy/secret_proxy")
async def journal_list():
    """
    获取私密代理
    marks: lblPageCount
    :param input:
    :return:
    """
    return_info = ReturnInfo()
    sql = "select proxy from proxyall_v1 where sources = 'taiyang' and stat=1"
    rows = await proxys_sql_conn.fetch_all(query=sql)
    result = [row[0] for row in rows]

    return_info.status = bools_string(True)
    return_info.msg_code = 200
    return_info.msg = ""
    return_info.data = result
    return return_info.todict()

@router.get("/getproxy/random_one")
async def journal_list():
    """
    随机获取一个私密代理
    marks: lblPageCount
    :param input:
    :return:
    """
    return_info = ReturnInfo()
    sql = "select proxy from proxyall_v1 where sources = 'taiyang' and stat = 1 order by rand() limit 1"
    rows = await proxys_sql_conn.fetch_all(query=sql)
    result = rows[0]

    return_info.status = bools_string(True)
    return_info.msg_code = 200
    return_info.msg = ""
    return_info.data = result
    return return_info.todict()
